﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace AppleAutoBuy.Common
{
    public static class Win32APIUnsafe
    {
        public delegate int EnumProc(IntPtr hWnd, ref IntPtr lParam);

        [DllImport("user32.dll")]
        public static extern bool SetCursorPos(int X, int Y);

        [DllImport("user32.dll")]
        public static extern void mouse_event(MouseEventFlag flags, int dx, int dy, uint data, UIntPtr extraInfo);

        [DllImport("user32.dll")]
        public static extern short GetKeyState(int nVirtKey);
        [DllImport("user32.dll")]
        public static extern void keybd_event(
                       byte bVk,
                       byte bScan,
                       uint dwFlags,
                       uint dwExtraInfo
                                               );

        [DllImport("user32.dll")] //User32.dll是Windows操作系统的核心动态库之一 
        public static extern int FindWindow(string lpClassName, string lpWindowName);
        //注意这个函数ObjectFromLresult的声明. 
        [DllImport("OLEACC.DLL", EntryPoint = "ObjectFromLresult")]
        public static extern int ObjectFromLresult(
        int lResult,
        ref System.Guid riid,
        int wParam,
        [System.Runtime.InteropServices.MarshalAs(UnmanagedType.Interface), System.Runtime.InteropServices.In, System.Runtime.InteropServices.Out]ref System.Object ppvObject
            //注意这个函数ObjectFromLresult的声明. 
        );

        [DllImport("user32.dll")]
        public static extern int EnumChildWindows(IntPtr hWndParent, EnumProc lpEnumFunc, ref  IntPtr lParam);

        [DllImport("user32.dll", EntryPoint = "GetClassNameA")]
        public static extern int GetClassName(IntPtr hwnd, StringBuilder lpClassName, int nMaxCount);

        [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
        public static extern uint RegisterWindowMessage(string lpString);

        [DllImport("user32.dll", EntryPoint = "SendMessageA")]
        public static extern int SendMessage(IntPtr hwnd, UInt32 wMsg, uint wParam, ref int lParam);

        [DllImport("user32.dll", EntryPoint = "SendMessageTimeoutA")]
        public static extern uint SendMessageTimeout(IntPtr hwnd, uint msg, int wParam, int lParam, int fuFlags, int uTimeout, out int lpdwResult);

    }
}
